package com.ruoyi.service.impl;

import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.Md5Utils;
import com.ruoyi.domain.BankLog;
import com.ruoyi.mapper.BankLogMapper;
import com.ruoyi.service.BankLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class BankLogServiceImpl implements BankLogService {

    @Resource
    private BankLogMapper bankLogMapper;

    @Override
    public BankLogMapper initDao() {
        return bankLogMapper;
    }


    /**
     * 导入用户数据
     *
     * @param bankLogList 用户数据列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @return 结果
     */

    @Override
    public String importBankLog(List<BankLog> bankLogList, Boolean isUpdateSupport)
    {
        if (StringUtils.isNull(bankLogList) || bankLogList.size() == 0)
        {
            throw new BusinessException("导入用户数据不能为空！");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        if (failureNum > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
}
